fix: normalize legacy task records on load; guard widget render#39
Merged
Conversation
Task files written before the blocking feature have no blockedBy/blocks/ metadata. TaskStore.load() deserialized them as-is, so consumers reading those fields unguarded (e.g. task.blockedBy.length in the widget) threw a TypeError. Because the widget renders on a pi-tui timer, the throw was uncaught and killed the whole pi process on the first render after upgrade. - Normalize every record at the load() boundary (normalizeTask): default metadata/blocks/blockedBy, with type guards for hand-edited files. This is the single fix point — the same unguarded accesses exist across the store and index mutation paths, not just the widget. - Wrap the widget render in try/catch returning a safe fallback, so a render error can never again escape to the TUI timer and crash the host. Fixes #33. Normalization approach based on #30 (thanks @arrokh); reported by @eSaadster. Co-authored-by: Noor Octavian (Alvin) Anwar <nooroctaviananwar@gmail.com>
…y-tasks # Conflicts: # test/task-store.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #33.Task files written before the blocking feature have noblockedBy/blocks/metadata.TaskStore.load()deserialized them as-is, and consumers read those fields unguarded (e.g.task.blockedBy.lengthin the widget). The first widget render on such a task threwTypeError: Cannot read properties of undefined (reading 'length'). Because the widget renders on a pi-tui timer, the throw was uncaught and killed the whole pi process — not just the extension — on the first render after upgrade. Unrecoverable without hand-editing the file.Fix
Two layers:
TaskStore.load→normalizeTask). Defaultsmetadata: {},blocks: [],blockedBy: [](with type guards for hand-edited files) plus defensive timestamp defaults. This is the correct single fix point: the same unguarded accesses exist across the store's mutation paths andindex.ts(including...task.metadataspreads that?.can't fix), not only the widget — normalizing once means every consumer receives a canonicalTask.renderWidgetnow wraps the build in try/catch and returns a safe fallback, so a render error can never again escape to the TUI timer and take down the host. Defense-in-depth against the whole class of "extension render throw crashes pi".Tests
test/task-store.test.ts— loading a legacy-shaped file (pending task, noblockedBy/blocks/metadata) yields a task with those fields defaulted, existing fields preserved.test/task-widget.test.ts— rendering a task missing legacy fields does not throw.Credit
Normalization approach based on #30 by @arrokh (thanks!) — this supersedes it. Reported by @eSaadster.
Test plan
npx tsc --noEmit— cleannpx vitest run— 190 passing (incl. 2 new)npx biome check src/ test/— clean